package com.wwy.producter;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;

/**
 * @author 王伟羽
 * @date 2024/3/14 9:36
 */
@RestController
@RequestMapping(value = "/topic")
public class TopicProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping(value = "/sendTopicMessage")
    public  String sendTopicMessage(String message){
        try {
            rabbitTemplate.convertAndSend("topic_exchange_one","a.123",message.getBytes("utf-8"));
            return "生产者发送消息成功";
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return "发送消息失败！";
        }
    }
}
